#pragma once

#include<pthread.h>
#include<iostream>
#include"Lock.hpp"

using namespace LockModule;

class cond
{
public:
    cond()
    {
        int n = ::pthread_cond_init(&_cond,nullptr);
        (void)n;
    }
    void wait(Mutex & mutex)//等待，也要让我们的线程释放曾经持有的锁！
    {
        int n = ::pthread_cond_wait(&_cond,mutex.lockptr());
    }
    void notify()//唤醒指定条件下的等待线程
    {
        int n = ::pthread_cond_signal(&_cond);
        (void)n;
    }
    void notifyall()//条件变量
    {
        int n = ::pthread_cond_broadcast(&_cond);
        (void)n;
    }
    ~cond()
    {
        int n = ::pthread_cond_destroy(&_cond);
    }
private:
    pthread_cond_t _cond;
};